<?php
Util::tsRegisterAssetJs('admin.js');
/** @var ContactoController $this */
/** @var Contacto $model */
$this->pageTitle = Contacto::label(2);
$this->menu = array(
    array('label' => Yii::t('AweCrud.app', 'Create'), 'icon' => 'plus', 'url' => array('create'), 'visible' => (Util::checkAccess(array('action_contacto_create')))),
//    array('label' => Yii::t('app', 'Grupos'), 'icon' => 'archive', 'url' => array('grupo'), 'visible' => (Util::checkAccess(array('action_cuenta_grupo')))),
    array('label' => Yii::t('app', 'Grupos'), 'icon' => 'archive', 'url' => array('grupo'),),
    array(
        'label' => 'Enviar SMS', 'icon' => 'comments', 'url' => '#', 'items' => array(
            array('label' => 'Todos', 'url' => '#', 'linkOptions' => array(
                    'onclick' => 'enviarSms(true)',
                ),
            ),
            array('label' => 'Seleccionados', 'url' => '#', 'linkOptions' => array(
                    'onclick' => 'enviarSms(false)',
                ),
            ),
        ),
        'visible' => (Util::checkAccess(array('action_sms_cargarFormularioSms'))),
        'htmlOptions' => array('data-target' => 'yw3')
    ),
    array(
        'label' => 'Enviar Email ', 'icon' => 'envelope', 'url' => '#', 'items' => array(
            array('label' => 'Todos', 'url' => '#', 'linkOptions' => array(
                    'onclick' => 'enviarMailContactos(true)',
                )),
            array('label' => 'Seleccionados', 'url' => '#', 'linkOptions' => array(
                    'onclick' => 'enviarMailContactos(false)',
                )),
        ), 'visible' => (Util::checkAccess(array('action_contacto_ajaxCargarMedioEnvio')))
    ),
    array(
        'label' => 'Registrar Llamada', 'icon' => 'phone', 'url' => '#', 'visible' => (Util::checkAccess(array('action_llamada_cargarFormularioLlamadaSaliente')) || Util::checkAccess(array('action_llamada_cargarFormularioLlamadaEntrante'))), 'items' => array(
            array('label' => 'Entrante', 'url' => '#', 'visible' => (Util::checkAccess(array('action_llamada_cargarFormularioLlamadaEntrante'))), 'linkOptions' => array(
                    'onclick' => 'crearLlamadaEntrante()'
                )),
            array('label' => 'Saliente', 'url' => '#', 'visible' => (Util::checkAccess(array('action_llamada_cargarFormularioLlamadaSaliente'))), 'linkOptions' => array(
                    'onclick' => 'crearLlamadaSaliente("")',
                ))
        ),
    ),
    array(
        'label' => 'Exportar', 'icon' => 'download-alt', 'url' => '#', 'items' => array(
            array('label' => 'Todos', 'url' => '#', 'linkOptions' => array(
                    'onclick' => 'ExporCont2(true)',),),
            array('label' => 'Seleccionados', 'url' => '#', 'linkOptions' => array(
                    'onclick' => 'ExporCont2(false)',),)
        ), 'visible' => (Util::checkAccess(array('action_contacto_exportExcel')))
    ),
);
?>

<div class="widget green">
    <div class="widget-title">
        <h4><i class="icon-group"></i> <?php echo Yii::t('AweCrud.app', 'Manage') ?> <?php echo Contacto::label(2) ?></h4>
        <span class="tools">
            <a href="javascript:;" class="icon-chevron-down"></a>
        </span>
    </div>
    <div class="widget-body form">
        <?php
        $this->widget('ext.Truulo.TruuloModuleSearch', array(
            'model' => $model,
            'grid_id' => 'contacto-grid',
        ));
        ?>
        <div style='overflow:auto'> 
            <?php
            $this->widget('ext.selgridview.BootSelGridView', array(
                'id' => 'contacto-grid',
                'type' => 'striped bordered hover advance',
                'template' => '{items}{summary}{pager}',
                'dataProvider' => $model->activos()->search(),
                'afterAjaxUpdate' => 'function(id,data){ $(\'span.star-rating > input\').rating(); $(\'div .rating-cancel\').hide(); ratingA();}',
                'selectableRows' => 2,
                'columns' => array(
                    array(
                        'class' => 'CCheckBoxColumn',
                    ),
                    array(
                        'name' => 'rating',
                        'type' => 'raw',
                        'value' => '$this->grid->controller->widget("CStarRating", array (
                        "name" => $data->id,
                        "id" => "rating_".$data->id,
                        "value" => $data->rating,
                        "allowEmpty" => false,
                        "maxRating" => 5,
                        "htmlOptions" => array("class"=>"star-rating"),
                        "callback"=>"js:function(){
                            rating($data->id);
                        }"
                    ), true)',
                        'htmlOptions' => array('class' => 'hidden-phone'),
                        'headerHtmlOptions' => array('style' => 'width:85px;', 'class' => 'hidden-phone'),
                        'filter' => false,
                        'sortable' => true,
                        'header' => '<i class="icon-star"></i><i class="icon-star"></i><i class="icon-star"></i><i class="icon-star"></i><i class="icon-star"></i>',
                        'visible' => Util::checkAccess(array("action_contacto_rating"))
                    ),
                    array(
                        'name' => 'nombre_completo',
                        'value' => 'CHtml::link($data->nombre_completo, Yii::app()->createUrl("crm/contacto/view",array("id"=>$data->id)))',
                        'type' => 'raw',
                    ),
                    array(
                        'name' => 'cuenta_id',
                        'value' => '$data->cuenta_id?CHtml::link($data->cuenta->nombre, Yii::app()->createUrl("crm/cuenta/view",array("id"=>$data->cuenta_id))):""',
                        'type' => 'raw',
                    ),
                    'cargo',
                    array(
                        'name' => 'grupo',
                        'value' => '!empty($data->grupos) ? $data->gruposToString() : null',
                        'type' => 'html'
                    ),
//                    array(
//                        'name' => 'telefono',
//                        'value' => '$data->telefono'
//                    ),
//                    array(
//                        'name' => 'celular',
//                        'value' => '$data->celular',
//                    ),
                    array(
                        'name' => 'owner_id',
                        'value' => 'Yii::app()->user->um->loadUserById($data->owner_id)->username',
                    ),
                    array(
                        'class' => 'CButtonColumn',
                        'template' => '{sms} {medioenvio} {llamada} {update} {delete}',
                        'buttons' => array(
                            'llamada' => array(
                                'label' => '<button class="btn btn-warning"><i class="icon-phone"></i></button>',
                                'options' => array('title' => 'Registrar llamada'),
                                'imageUrl' => false,
                                'url' => '$data->id',
                                'click' => 'function() {crearLlamadaSaliente($(this).attr("href")); return false;}',
                                'visible' => 'Util::checkAccess(array("action_llamada_cargarFormularioLlamadaSaliente"))'
                            ),
                            'sms' => array(
                                'label' => '<button class="btn btn-success"><i class="icon-comments"></i></button>',
                                'options' => array('title' => 'Enviar SMS'),
                                'imageUrl' => false,
                                'url' => '$data->id',
                                'click' => 'function() {enviarSmsSolo($(this).attr("href")); return false;}',
                                'visible' => 'Util::checkAccess(array("action_sms_cargarFormularioSms"))'
                            ),
                            /* Botones para envios de Mail sin medio de envio */
//                            'email' => array(
//                                'label' => '<button class="btn btn-inverse"><i class="icon-envelope"></i></button>',
//                                'options' => array('title' => 'Enviar Correo Electrónico'),
//                                'imageUrl' => false,
//                                'url' => '$data->id',
//                                'click' => 'function() {enviarMailSolo($(this).attr("href"),"contacto/admin"); return false;}',
//                                'visible' => 'Util::checkAccess(array("action_mail_cargarFormularioMail"))'
//                            ),
//                            'mandrill' => array(
//                                'label' => '<button class="btn btn-inverse"><i class="icon-envelope"></i></button>',
//                                'options' => array('title' => 'Enviar Correo Electrónico Mandrill'),
//                                'imageUrl' => false,
//                                'url' => '$data->id',
//                                'click' => 'function() {enviarMailMandrillSolo($(this).attr("href"),"contacto/admin"); return false;}',
//                            // 'visible' => 'Util::checkAccess(array("action_mail_cargarFormularioMail"))'
//                            ),
                            /*                             * ************************************************* */
                            'medioenvio' => array(
                                'label' => '<button class="btn btn-inverse"><i class="icon-envelope"></i></button>',
                                'options' => array('title' => 'Enviar Correo Electrónico'),
                                'imageUrl' => false,
                                'url' => '$data->id',
                                'click' => 'function() {medioEnviarMailSolo($(this).attr("href"),"contacto/admin"); return false;}',
                                'visible' => 'Util::checkAccess(array("action_contacto_ajaxCargarMedioEnvio"))'
                            ),
                            'update' => array(
                                'label' => '<button class="btn btn-primary"><i class="icon-pencil"></i></button>',
                                'options' => array('title' => 'Actualizar'),
                                'imageUrl' => false,
                                'visible' => 'Util::checkAccess(array("action_contacto_update"))'
                            ),
                            'delete' => array(
                                'label' => '<button class="btn btn-danger"><i class="icon-trash"></i></button>',
                                'options' => array('title' => 'Eliminar'),
                                'imageUrl' => false,
                                'visible' => 'Util::checkAccess(array("action_contacto_delete"))'
                            ),
                        ),
                        'htmlOptions' => array(
                            'width' => '206px'
                        )
                    ),
                ),
            ));
            ?>
        </div>
    </div>
</div>
<form id="formId" method="post" target="blank">
    <input type="hidden" id="id_contac" name="Contactos">
    <input type="hidden" id="id_grupo" name="Grupo">
</form>

